From c215f5002040c189f9452732fd15752f3368c4ff Mon Sep 17 00:00:00 2001 From: "emellor@leeni.uk.xensource.com" Date: Wed, 14 Dec 2005 11:54:39 +0000 Subject: [PATCH] Added a stress test for the Xenstore-Python interface layer. Signed-off-by: Ewan Mellor --- tools/python/setup.py | 1 + .../xen/xend/xenstore/tests/__init__.py | 2 + .../xen/xend/xenstore/tests/stress_xs.py | 121 ++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 tools/python/xen/xend/xenstore/tests/__init__.py create mode 100644 tools/python/xen/xend/xenstore/tests/stress_xs.py diff --git a/tools/python/setup.py b/tools/python/setup.py index 79b9730a1a..49f79e1b87 100644 --- a/tools/python/setup.py +++ b/tools/python/setup.py @@ -46,6 +46,7 @@ setup(name = 'xen', 'xen.xend.tests', 'xen.xend.server.tests', + 'xen.xend.xenstore.tests', 'xen.xm.tests' ], ext_package = "xen.lowlevel", diff --git a/tools/python/xen/xend/xenstore/tests/__init__.py b/tools/python/xen/xend/xenstore/tests/__init__.py new file mode 100644 index 0000000000..139597f9cb --- /dev/null +++ b/tools/python/xen/xend/xenstore/tests/__init__.py @@ -0,0 +1,2 @@ + + diff --git a/tools/python/xen/xend/xenstore/tests/stress_xs.py b/tools/python/xen/xend/xenstore/tests/stress_xs.py new file mode 100644 index 0000000000..647eb8bdd7 --- /dev/null +++ b/tools/python/xen/xend/xenstore/tests/stress_xs.py @@ -0,0 +1,121 @@ +# This library is free software; you can redistribute it and/or +# modify it under the terms of version 2.1 of the GNU Lesser General Public +# License as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# Copyright (c) 2005 XenSource Ltd + + +import random +import sys +import threading +import time + +import xen.lowlevel.xs + +from xen.xend.xenstore import xsutil +from xen.xend.xenstore.xstransact import xstransact +from xen.xend.xenstore.xswatch import xswatch + + +PATH = '/tool/stress_xs' + + +def stress(): + xstransact.Remove(PATH) + xstransact.Mkdir(PATH) + + xswatch(PATH, watch_callback) + + def do(f): + t = threading.Thread(target=stress_write) + t.setDaemon(True) + t.start() + + do(stress_write) + do(stress_get_domain_path) + do(stress_get_domain_path_xsutil) + do(stress_open_close) + + while True: + # Wait for Ctrl-C. + time.sleep(100000000) + + +def stress_write(): + xstransact.Write(PATH, 'key', '1') + while True: + val = xstransact.Gather(PATH, ('key', int)) + xstransact.Store(PATH, ('key', val + 1)) + + random_sleep() + + +def stress_get_domain_path(): + xs_handle = xen.lowlevel.xs.xs() + + domid = 0 + while True: + xs_handle.get_domain_path(domid) + domid += 1 + + random_sleep() + + +def stress_get_domain_path_xsutil(): + domid = 0 + while True: + xsutil.GetDomainPath(domid) + domid += 1 + + random_sleep() + + +def stress_open_close(): + while True: + xs_handle = xen.lowlevel.xs.xs() + + try: + try: + trans = xs_handle.transaction_start() + val = int(xs_handle.read(trans, PATH + '/key')) + xs_handle.write(trans, PATH + '/key', str(val + 1)) + xs_handle.transaction_end(trans, False) + except: + xs_handle.transaction_end(trans, True) + + random_sleep() + finally: + del xs_handle + + +def watch_callback(path): + random_sleep() + return True + + +def random_sleep(): + d = random.randint(-50000, 500) + if d > 0: + time.sleep(d / 1000.0) + + +def main(argv = None): + if argv is None: + argv = sys.argv + + stress() + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) -- 2.30.2